﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Photos
{
    public partial class AddNewPhoto : ModuleCompanyBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btn_Click(object sender, EventArgs e)
        {
            var photo = new cp_Photo();

            //kiem tra quyen hop le 
            string filename;
            if (file.HasFile)
            {
                filename = Guid.NewGuid() + file.FileName;
                file.SaveAs(PathPhysicalImage + filename);

                SaveThumb(filename, 90, 90);

            }
            else
            {
                filename = "noimage.gif";
            }


            photo.Img = filename;
            if (title.Text != null) {
                photo.Title = title.Text.Trim();
            }
            if (descript.Text != null) {
                photo.Description = descript.Text;
            }
            photo.CreateDate = DateTime.Now;

            DB.cp_Photos.InsertOnSubmit(photo);
            DB.SubmitChanges();

            this.txtMs.Text = "đã thêm thành công ảnh";

        }
    }
}